package GUI;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JOptionPane;

public class MButton extends JButton
{
	private static boolean waitFlag=false;
	private static boolean wireFlag=false;
	private static int x1,y1,x2,y2;
	MButton(String a)
	{
		super(a);
		action();
	}
	MButton(String a,Icon b)
	{
		super(a,b);
		action();
	}
	MButton(Icon a)
	{
		super(a);
		action();
	}
	public void action()
	{
		this.addMouseListener(new MouseListener(){
		public void mouseClicked(MouseEvent event) 
		{
		}

		@Override
		public void mouseEntered(MouseEvent arg0) {
			// TODO Auto-generated method stub
			
		}

		@Override
		public void mouseExited(MouseEvent arg0) {
			// TODO Auto-generated method stub
			
		}

		@Override
		public void mousePressed(MouseEvent event) 
		{
			if(waitFlag==true)
			{
				JOptionPane.showMessageDialog(null," !!!Second!!! ");
				waitFlag=false;
				x2=event.getXOnScreen();
				y2=event.getYOnScreen()- WorkSpaceScreen.toolbar.getHeight()- WorkSpacePanel.getPanelHolderHt();
				WorkSpacePanel.Draw(x1,y1,x2,y2);
				updateUI();
				WorkSpaceScreen.toggleWireFlag();
				wireFlag=true;
			}
			else if(WorkSpaceScreen.getWireFlag()==true)	
			{
				waitFlag=true;
				JOptionPane.showMessageDialog(null," !!!First!!! ");
				x1=event.getXOnScreen();
				y1=event.getYOnScreen()- WorkSpaceScreen.toolbar.getHeight()- WorkSpacePanel.getPanelHolderHt();
				
			}

			
		}

		@Override
		public void mouseReleased(MouseEvent arg0) {
			// TODO Auto-generated method stub
			
		}
		
	});
	}
}
